<template>
	<view>
		<view class="Receiving">
			<view class="zuo">、
			</view>
			<view class="you wzstyle">
				填写收货信息
			</view>
		</view>
		<view class="box" @click="tiao">
			<view class="leftbox">
				<uni-icons type="location" size="24" class="dinwei"></uni-icons>
				<view class="zhong">
					<view class="zhongBox">
						<view class="Zuo wzstyle">
							<view class="zuoid">
								{{nowHarvest.name}}
							</view>
							<view class="">
								{{nowHarvest.phone}}
							</view>

						</view>
						<view class="You wzstyle">
							{{nowHarvest.area}}
						</view>
					</view>
					<view class="default wzstyle" v-if="nowHarvest.type==1">
						<text wzstyle>默认</text>
					</view>
				</view>
			</view>

			<view class="rightbox">
				<uni-icons type="right" size="30"></uni-icons>
			</view>
		</view>
		<view class="Receiving">
			<view class="zuo">、
			</view>
			<view class="you wzstyle">
				商品信息
			</view>
		</view>
		<view class="commodity" @click="tiaozhuan">
			<view class="commodityZuo">
				<view class="commodityImg">
					<image :src="'../../static/Mall/'+dataArr.goodsImg" class='tp'></image>
				</view>
				<view class="information">
					<view class="top wzstyle">
						{{dataArr.goodsName}}
					</view>
					<view class="top wzstyle yanse">
						常规
					</view>
					<view class="top wzstyle red">
						积分:{{dataArr.goodsIntegration}}
					</view>
				</view>
			</view>
			<view class="commodityYuo wzstyle blue">
				X1
			</view>
		</view>
		<view class="total">
			<view class=" wzstyle">
				商品合计
			</view>
			<view class="wzstyle">
				{{dataArr.goodsIntegration}}
			</view>
		</view>
		<view class="total1">
			<view class="wzstyle">
				运费
			</view>
			<view class="FreeMail">
				<view class="mianyou wzstyle">
					<text>免邮</text>
				</view>
				<view class="money wzstyle">
					¥0.00
				</view>
			</view>
		</view>
		<view class="footer-box">
			<uni-goods-nav @click="onClick" :options="options" :button-group="buttonGroup" @buttonClick="pay" />
		</view>
	</view>
</template>

<script>
	import {

		reactive
	} from 'vue';
	import store from '../../store/index.js';
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app';
	import myRequest from '../../utils/myRequest.js';
	export default {
		setup() {
			let data = reactive({
				goodsArr: [],
				vipData: {},
				nowHarvest: "",
				goodsId: "",
				shouid: "",
				Harvest: "",
				dataArr: "",
				options: [{
						icon: 'chat',
						text: '客服'
					},
					// {

					// 	icon: 'chat',
					// 	text: '应付积分'
					// }
				],
				buttonGroup: [{
					text: '立即下单',
					backgroundColor: '#3478F7',
					color: '#ffffff'
				}],
				onClick(e) {
					uni.showToast({
						title: `点击${e.content.text}`,
						icon: 'none'
					})
				},
				tiaozhuan() {
					// uni.navigateTo({
					// 	url: '/pages/jifen/shangpin'
					// });
					data.random()
				},
				tiao() {
					uni.navigateTo({
						url: '/pages/Mall/HarvestSelect'
					});
				},

				CommodityInformation: function(i) {
					myRequest({
						url: "/getgoodsId",
						method: 'POST',
						data: {
							id: i
						},
					}).then((res) => {
						if (res.data.code == 200) {

							data.dataArr = res.data.data[0]

							console.log(data.dataArr)

						}
					})



				},
				HarvestRequest: function() {
					myRequest({
						url: "/sC_DefaultHarvest",
						method: 'POST',
						data: {
							vipId: store.state.userdata[0].vipId,
						},
					}).then((res) => {
						if (res.data.code == 200) {
							store.commit('editUserOrderHarvest', res.data.data);
							for (let i = 0; i < res.data.data.length; i++) {
								if (res.data.data[i].type == 1) {
									store.commit('editNowUserOrderHarvest', res.data.data[i]);
									break;
								}
							}
							data.NowHarvest();
						}
					})
				},
				pay: function() {
						console.log(data.orderNum)
							console.log(data.orderTime)
					if (data.vipData.vipIntegration >= data.dataArr.goodsIntegration) {
						myRequest({
							url: "/addOrder",
							method: 'POST',
							data: {
								goodsId: data.goodsId,
								vipId: data.vipData.vipId,
								num: 1,
								consignee: data.nowHarvest.name,
								shipAddress: data.nowHarvest.area + data.nowHarvest.place,
								phone: data.nowHarvest.phone,
								payMethod: 0,
								time: data.orderTime,
								logisticsInfo: '待发货',
								money: data.dataArr.goodsIntegration,
								orderMoney: data.dataArr.goodsIntegration,
								goodsXing: '常规',
								orderNum: data.orderNum,
								goodsImg:data.dataArr.goodsImg

							},
						}).then((res) => {
							if (res.data.code == 200) {
							myRequest({
									url: "/editIntegration",
									method: 'POST',
									data:{
											vipId: data.vipData.vipId,
											integration: data.dataArr.goodsIntegration,
											integrationAdd:0
									}
								})
								
								uni.navigateTo({
									url: '/pages/jifen/duihuan?id='+data.dataArr.goodsId
								});
									
							}
						})
					} else {
						uni.showToast({
							title: '您的积分不足',
							duration: 2000,
							icon:'error'
						});
					}
				},



				NowHarvest: function() {
					data.nowHarvest = store.state.nowUserOrderHarvest;
					console.log(data.nowHarvest)
				},
				random: function() {
					let Range = 10
					let num = 1
					let rand = ''
					for (let i = 0; i < 8; i++) {
						let randdata = parseInt(Math.random() * Range);
						rand += randdata

					}
					console.log(rand)
				}
			})
			onLoad((option) => {

				data.goodsId = option.id;
				data.CommodityInformation(option.id);
				data.HarvestRequest(option.id);
				data.vipData = store.state.userdata[0];
				data.orderTime = new Date().toLocaleString('chinese', {
					hour12: false
				});
					data.orderNum = new Date().getTime();
				console.log(data.vipData.vipIntegration)
				console.log(data.goodsId)

			});
			onShow(() => {
				data.NowHarvest();
			})
			return data
		}






	}
</script>

<style lang="scss">
	.zuoid {
		margin-right: 20rpx;
	}

	.yanse {
		color: #999999;
	}

	.footer-box {
		position: fixed;
		bottom: 0;
		z-index: 999;
		width: 100%;
	}

	.example-body {
		padding: 0;
		/* #ifndef APP-NVUE */
		display: block;
		/* #endif */
	}

	.goods-carts {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		position: fixed;
		left: 0;
		right: 0;
		/* #ifdef H5 */
		left: var(--window-left);
		right: var(--window-right);
		/* #endif */
		bottom: 0;
	}

	.mianyou text {
		padding: 5rpx;
		color: #F3A73F;
		border-radius: 20rpx;
		border: 1px solid #F3A73F;
	}

	.money {
		margin-left: 15rpx;
	}

	.FreeMail {
		display: flex;
	}

	.total {
		border-top: 1px solid #B9B9B9;
		border-bottom: 1px solid #B9B9B9;
		height: 100rpx;
		line-height: 100rpx;
		display: flex;
		justify-content: space-between;
		padding-left: 25rpx;
		padding-right: 25rpx;
	}

	.total1 {

		border-bottom: 1px solid #B9B9B9;
		height: 100rpx;
		line-height: 100rpx;
		display: flex;
		justify-content: space-between;
		padding-left: 25rpx;
		padding-right: 25rpx;
	}

	.blue {
		color: #0000FF;
	}

	.red {
		color: #FF0000;
	}

	.top {
		margin-bottom: 15rpx;
	}

	.tp {
		width: 150rpx;
		height: 150rpx;
		margin-right: 10rpx;
	}

	.commodityZuo {
		display: flex;
	}

	.commodity {
		display: flex;
		border-top: 1px solid #B9B9B9;
		border-bottom: 1px solid #B9B9B9;
		justify-content: space-between;
		padding: 50rpx;
		margin-bottom: 30rpx;
	}

	.wzstyle {
		font-size: 30rpx;
	}

	.default text {
		padding: 5rpx;
		color: #F3A73F;
		border-radius: 20rpx;
		border: 1px solid #F3A73F;
	}

	.dinwei {
		margin-top: 45rpx;
	}

	.leftbox {
		display: flex;
	}

	.Zuo {
		display: flex;
		margin-bottom: 20rpx;
	}

	.zhong {
		display: flex;
	}

	.box {
		border-top: 1px solid #B9B9B9;
		border-bottom: 1px solid #B9B9B9;
		justify-content: space-between;
		display: flex;
		padding: 50rpx;
	}

	.Receiving {
		padding-top: 40rpx;
		padding-left: 25rpx;
		height: 90rpx;
		line-height: 46rpx;
		display: flex;

	}

	.zuo {
		width: 10rpx;
		height: 40rpx;
		background-color: #007AFF;
		margin-right: 15rpx;
	}
</style>
